package com.imast.android.bys.ui;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.imast.android.bys.R;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

public class Seguimiento extends FragmentActivity {
	
	private GoogleMap map;
	
	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		
		setContentView(R.layout.fragment_seguimiento);
		
		/*map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapSeguimiento)).getMap();
		
		if (getIntent() != null){
			double latitud = getIntent().getDoubleExtra("latitud", 0);
			double longitud = getIntent().getDoubleExtra("longitud", 0);
			
			Log.e("UBICACION", latitud + "-" + longitud);
			
		    CameraUpdate center=
		            CameraUpdateFactory.newLatLng(new LatLng(latitud, longitud));
		        CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);

		        map.moveCamera(center);
		        map.animateCamera(zoom);
		}*/
		
		
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
		LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
			      new IntentFilter("com.imast.android.bys.myBroadcast"));
		
	}
	
	@Override
	protected void onPause() {
		LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
		super.onPause();
	}
	
	private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
		  @Override
		  public void onReceive(Context context, Intent intent) {
		    double latitud = intent.getDoubleExtra("latitud", 0);
		    double longitud = intent.getDoubleExtra("longitud", 0);
		    Log.e("receiver", "Got message: " + latitud + " - " + longitud);
		  }
	};
	
}
